#!/bin/bash

files=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS

count=0
for file in $files
do
    dir=`dirname $file`
    while [[ ${#dir} > 1 ]]
    do
        if [[ -d $dir/.git ]]
        then
            res=`git ls-files $file`
            if [[ x$res == x ]]
            then
                git add $files
                (( count += 1 ))
            else
                res=`git diff --name-only $files`
                if [[ x$res != x ]]
                then
                    git add $files
                    (( count += 1 ))
                fi
            fi
            break
        else
            dir=`dirname $dir`
        fi
    done
done

if (( $count > 0 ))
then
    dt=`date +"%Y-%m-%d %H:%M:%S"`
    git commit -m "update: $dt"
    git push
    notify-send "git push success"
else
    notify-send "no file need git push"
fi
